package frame.laxcen.test;

import frame.laxcen.BaseFrame;
import frame.laxcen.request.Request_0010_10;
import frame.laxcen.response.Response_0010_10;
import frame.laxcen.util.FrameUtil;
import frame.laxcen.module.RFIDReader;
import tcpclient.v2.RFIDClient;
import frame.util.FlowUtil;
import frame.util.Ref;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.List;

public class RFIDReader_Single_Split_Read_By_IsUpload {

    public static void main(String[] args) throws IOException {

        RFIDReader reader = new RFIDReader(new RFIDClient(1 << 20, 1024));

        if(reader.tryConnect(new InetSocketAddress("192.168.1.116", 9090), 3000)) {

            System.out.println("连接成功！");

            Request_0010_10.RequestTemplate template = new Request_0010_10.RequestTemplate();

            template.useAntenna_1();

            template.standerSingleRead();

            Ref<List<BaseFrame>> isUpload = Ref.empty(), isNotUpload = Ref.empty();

            reader.blockRead(new Request_0010_10(template), isUpload, isNotUpload, 3000);

            System.out.println("控制消息");

            isUpload.ifPresent((frames) -> frames.forEach((frame) -> FlowUtil.silent(frame, (f) -> FrameUtil.printResponse(new Response_0010_10(frame)))));

            System.out.println("标签消息");

            isNotUpload.ifPresent((frames) -> frames.forEach((frame) -> FlowUtil.silent(frame, (f) -> FrameUtil.printResponse(new Response_0010_10(frame)))));

            if(reader.tryClose()) System.out.println("关闭连接！");
        }
    }
}
